﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Dsl.Ped.Framework.Projections.CollectionProjections.ExpandableCollection"
    xmlns:converters="clr-namespace:Dsl.Ped.Common.Converters;assembly=DSLCommon"
    xmlns:buttonActionSelector="clr-namespace:Dsl.Ped.Controls.ButtonActionSelector;assembly=DSLPedControls"
    xmlns:actionBorder="clr-namespace:Dsl.Ped.Controls.ActionBorder;assembly=DSLPedControls"
    xmlns:converters1="clr-namespace:Dsl.Ped.Common.Converters"
    xmlns:projectiveObject="clr-namespace:Dsl.Ped.Framework.WPFControls.ProjectiveObject"
    xmlns:common="clr-namespace:Dsl.Ped.Framework.Common">

    <converters:OrientationToDockConverter x:Key="orientationToDockConverter"/>
    <converters:ObjectToTypeCheckConverter x:Key="objectToTypeCheckConverter"/>
    <converters:ListBoxItemToPositionConverter x:Key="listBoxItemToPositionConverter"/>
    <converters1:ProjectiveObjectConverter x:Key="projectiveObjectConverter"/>

    <Style TargetType="{x:Type local:ExpandableCollectionProjection}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ExpandableCollectionProjection}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        
                        <buttonActionSelector:ButtonActionSelectorControl
                            Content="+"
                            Grid.Column="0"
                            Commands="{TemplateBinding Commands}">   
                        </buttonActionSelector:ButtonActionSelectorControl>
                        
                        <ListBox Grid.Column="1"
                              ItemsSource="{TemplateBinding ItemsSource}"
                              Background="{TemplateBinding Background}"
                              BorderThickness="{TemplateBinding BorderThickness}"
                              KeyboardNavigation.IsTabStop="False"
                              x:Name="listBox">
                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <WrapPanel Orientation="Horizontal"/>
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="{x:Type ListBoxItem}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Converter={StaticResource objectToTypeCheckConverter}, ConverterParameter={x:Type common:IProjective}}" Value="True">
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate>
                                                        <StackPanel Orientation="Horizontal">
                                                            <actionBorder:ActionBorderControl 
                                                        Command="{Binding Path=RemoveObjectCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ExpandableCollectionProjection}, Mode=OneWay}"
                                                        CommandParameter="{Binding}">
                                                                <projectiveObject:ProjectiveObjectUserControl ProjectiveObject="{Binding}"/>
                                                            </actionBorder:ActionBorderControl>
                                                            <buttonActionSelector:ButtonActionSelectorControl
                                                        Content="+"
                                                        Commands="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ExpandableCollectionProjection}, Path=Commands}"
                                                        CommandParameter="{Binding}">
                                                            </buttonActionSelector:ButtonActionSelectorControl>
                                                        </StackPanel>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding Converter={StaticResource objectToTypeCheckConverter}, ConverterParameter={x:Type common:IProjection}}" Value="True">
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate>
                                                        <ContentPresenter Content="{Binding View}"/>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </DataTrigger>
                                    </Style.Triggers>
                                    <Setter Property="KeyboardNavigation.IsTabStop" Value="False" />
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate>
                                                <ContentPresenter Content="{Binding}"/>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ListBox.ItemContainerStyle>
                        </ListBox>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>